package com.yic.module.base.dal.mysql.workshop;

import java.util.*;

import com.yic.framework.common.pojo.PageResult;
import com.yic.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.yic.framework.mybatis.core.mapper.BaseMapperX;
import com.yic.module.base.dal.dataobject.workshop.WorkshopDO;
import org.apache.ibatis.annotations.Mapper;
import com.yic.module.base.controller.admin.workshop.vo.*;

/**
 * 生产车间 Mapper
 *
 * @author 系统管理员
 */
@Mapper
public interface WorkshopMapper extends BaseMapperX<WorkshopDO> {

    default PageResult<WorkshopDO> selectPage(WorkshopPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<WorkshopDO>()
                .likeIfPresent(WorkshopDO::getName, reqVO.getName())
                .eqIfPresent(WorkshopDO::getCode, reqVO.getCode())
                .eqIfPresent(WorkshopDO::getStatus, reqVO.getStatus())
                .eqIfPresent(WorkshopDO::getFactoryId, reqVO.getFactoryId())
                .orderByDesc(WorkshopDO::getId));
    }

    default List<WorkshopDO> selectList(WorkshopExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<WorkshopDO>()
                .likeIfPresent(WorkshopDO::getName, reqVO.getName())
                .eqIfPresent(WorkshopDO::getCode, reqVO.getCode())
                .eqIfPresent(WorkshopDO::getStatus, reqVO.getStatus())
                .eqIfPresent(WorkshopDO::getFactoryId, reqVO.getFactoryId())
                .orderByDesc(WorkshopDO::getId));
    }

    default WorkshopDO selectByName(String name) {
        return selectOne(new LambdaQueryWrapperX<WorkshopDO>()
                .eq(WorkshopDO::getName, name));
    }

    default WorkshopDO selectByCode(String code) {
        return selectOne(new LambdaQueryWrapperX<WorkshopDO>()
                .eq(WorkshopDO::getCode, code));
    }

    default List<WorkshopDO> selectList(Collection<Long> ids, Collection<Integer> statuses) {
        return selectList(new LambdaQueryWrapperX<WorkshopDO>()
                .inIfPresent(WorkshopDO::getId, ids)
                .inIfPresent(WorkshopDO::getStatus, statuses));
    }
}
